package com.changgou.goods.dao;

import com.changgou.goods.pojo.Spu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface SpuMapper extends Mapper<Spu> {
    @Select("select options from tb_para where template_id = #{id}")
    String findTemplateById(Long id);

    /**
     * 查询总商品数量
     * @return
     */
    @Select("select count(*) from tb_spu")
    Long findCount();

    /**
     * 已上架商品数量
     * @return
     */
    @Select("select count(*) from tb_spu where is_marketable = 1")
    Long findOnTable();

    /**
     * 未上架商品数量
     * @return
     */
    @Select("select count(*) from tb_spu where is_marketable = 0")
    Long findOffTable();

    /**
     * 待审核商品数量
     * @return
     */
    @Select("select count(*) from tb_spu where status = 2")
    Long findPending();

    /**
     * 未通过商品数量
     * @return
     */
    @Select("select count(*) from tb_spu where status = 0")
    Long findFail();

    /**
     * 全部商品的分页查询
     * @param start
     * @param size
     * @return
     */
    @Select("select id , image , name , sn , is_marketable , sale_Num , status from tb_spu limit #{start} , #{size}")
    List<Spu> findPage(@Param("start") int start, @Param("size") int size);

    /**
     * 是否上架的分页查询
     * @param is_marketable
     * @param start
     * @param size
     * @return
     */
    @Select("select id , image , name , sn , is_marketable , sale_Num , status from tb_spu where is_marketable = #{is_marketable} limit #{start} , #{size}")
    List<Spu> findPageByIs(@Param("is_marketable") String is_marketable,@Param("start") int start, @Param("size") int size);

    /**
     * 审核情况的分页查询
     * @param status
     * @param start
     * @param size
     * @return
     */
    @Select("select id , image , name , sn , is_marketable , sale_Num , status from tb_spu where status = #{status} limit #{start} , #{size}")
    List<Spu> findPageByStatus(@Param("status") String status,@Param("start") int start, @Param("size") int size);
}
